
// 手机、PC 全局公用文件，放到所有自定义 js 的前面！

myhost = window.location.host;

if(myhost.indexOf("www.") === 0 || myhost.indexOf("xxx.com") >= 0) {
	env = "production";
	apidomain = "http://api.xxx.com/";
}
else if(myhost.indexOf("testing.") === 0){
	env = "testing";
	apidomain = "http://testing.api.xxx.com/";
}
else{
	env = "development";
	apidomain = "http://dev.api.xxx.com/";
}

function is_mobile() {
	let ua = navigator.userAgent;
	return /Android|webOS|iPhone|iPad|iPod|iOS|Phone|BlackBerry|mobile|Opera Mini|webmate/i.test(ua);
}

//自动跳转
function auto_redirect() {
    let oldUrl = window.location.href;
    let newUrl = oldUrl.replace(is_mobile() ? /\/pc\// : /\/m\//, is_mobile() ? '/m/' : '/pc/');
    (oldUrl === newUrl) || (location.href = newUrl);
}

//auto_redirect();

function get_cookie(name) {
    var arr,reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if(arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

var access_token = get_cookie("access_token");

if(access_token) {
    $.ajaxSetup({
        headers: {
            "Authorization": "Bearer " + access_token,
        }
    });
}
